<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增推荐')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-recommend-add">
            <div class="form-group">
                <label class="col-sm-3 control-label">推送的时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="sendTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">推送描述：</label>
                <div class="col-sm-8">
                    <input name="content" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">判断是否已推送：</label>
                <div class="col-sm-8">
                    <select name="isSend"  >
                        <option value="0">是</option>
                        <option value="1">否</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-8">
                    <input type="hidden" name="appids" id="appids">
                </div>
            </div>
        </form>
        <div class="container-div">
            <div class="row">
                <div class="col-sm-12 search-collapse">
                    <form id="formId">
                        <div class="select-list">
                            <ul>
                                <li>
                                    <label>序列号：</label>
                                    <input type="text" name="serialNum"/>
                                </li>
                                <li>
                                    <label>应用名称：</label>
                                    <input type="text" name="name"/>
                                </li>
                                <li>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>
                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/recommend"
        $("#form-recommend-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length != 0) {
               $('#appids').val(rows.join());
                console.log($('#appids').val());
            }

            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-recommend-add').serialize());
            }
        }

        $("input[name='addtime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='sendTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(function() {
            $('.summernote').summernote({
                lang: 'zh-CN',
                callbacks: {
                    onChange: function(contents, $edittable) {
                        $("input[name='" + this.id + "']").val(contents);
                    },
                    onImageUpload: function(files) {
                        var obj = this;
                    	var data = new FormData();
                    	data.append("file", files[0]);
                    	$.ajax({
                            type: "post",
                            url: ctx + "common/upload",
                    		data: data,
                    		cache: false,
                    		contentType: false,
                    		processData: false,
                    		dataType: 'json',
                    		success: function(result) {
                    		    if (result.code == web_status.SUCCESS) {
                    		        $('#' + obj.id).summernote('insertImage', result.url);
                    		    } else {
                    		        $.modal.alertError(result.msg);
                    		    }
                    		},
                    		error: function(error) {
                    		    $.modal.alertWarning("图片上传失败。");
                    		}
                    	});
                    }
                }
            });
        });
        var prefix2 = ctx + "system/appsys";
        $(function() {
            var options = {
                url: prefix2 + "/list",
                uniqueId: '',
                modalName: "应用详细内容",
                pageSize: 2000,
                pagination:false,
                showRefresh:false,
                clickToSelect:true,
                columns: [
                    {
                        checkbox: true
                    },
                    {
                        field: 'id',
                        title: 'id',
                        visible: false
                    },
                    {
                        field: 'serialNum',
                        title: '序列号：'
                    },
                    {
                        field: 'name',
                        title: '应用名称'
                    },
                    {
                        field: 'url',
                        title: '网址'
                    }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>
